package com.bcn.login_mybatis_demo.config;

import com.bcn.login_mybatis_demo.config.JwtAuthenticationInterceptor; // 确保路径正确
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private JwtAuthenticationInterceptor jwtAuthenticationInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册拦截器并添加拦截路径
        registry.addInterceptor(jwtAuthenticationInterceptor)
                .addPathPatterns("/**") // 拦截所有请求
                .excludePathPatterns(
                        "/user/login" // 排除登录接口
//                        "/register", // 排除注册接口
//                        "/error", // 排除错误处理接口
//                        // 可以继续添加其他不需要JWT验证的接口路径
//                        "/swagger-**/**"
                );
    }
}
